﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLayer.EF;
using EntityLayer;

namespace DataLayer.CLASES_DAO
{
    public class clsT_RecursoDAO
    {
        private BD_GESTIONVISITAEntities ContextoDeObjs = new BD_GESTIONVISITAEntities();
        public Boolean Insertar(T_Recurso obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_Recurso", obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public Boolean Modificar(T_Recurso obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_Recurso", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public Boolean Eliminar(T_Recurso obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_Recurso", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public List<T_Recurso> listar()
        {
            List<T_Recurso> lista = new List<T_Recurso>();
            try
            {
                var q = from c in ContextoDeObjs.T_Recurso
                        select c;
                lista = q.ToList();
            }
            catch (Exception)
            {
                lista = null;
                throw;
            }
            return lista;
        }


    }
}
